<?php

/*
  
  Project: CI Forum
  Type: PHP and database
  Desc: Contains all functions related to categories.
  Author: Yash Bharadwaj
 
 

*/

class Post_model extends Model {

    function Post_model() {
    // Call the Model constructor
        parent::Model();
        $this->load->helper('date');
        $this->load->library('table');

    }

    function create_reply() {

        $forum_title=$this->uri->segment(3);
        $thread_title=$this->uri->segment(4);

        if($this->input->post('enable_emoticons'))
            $emoticons = 1;
        else
            $emoticons = 0;

        if($this->input->post('enable_signature'))
            $signature = 1;
        else
            $signature = 0;

        if($this->input->post('enable_notification'))
            $notification = 1;
        else
            $notification = 0;

        if($this->input->post('make_hidden'))
            $hidden = 1;
        else
            $hidden = 0;

        $insert = array(
            'post_id' => '',
            'post_content' => $this->input->post('post_content'),
            'author_id'	=> $this->session->userdata('DX_user_id') ,
            'thread_title' => $thread_title,
            'forum_title' => $forum_title,
            'uploaded_files' =>'',
            'enable_notification'=>$notification,
            'reason_content'=>'',
            'icon_id'=>'',
            'make_hidden'=>$hidden,
            'posted_date' => now(),
        );
        $result= $this->db->insert('board_posts', $insert);

        $update= array('latest_entry_date'=>now());
        $this->db->where('url_title',$thread_title);
        $check= $this->db->update('board_threads', $update);

        $data['title']="Information Page";
        $data['header']="Information";


        if($result) {
            $data['time']="1";
            $data['info']="<p>Post is created Succesfully</p><p>Wait for auto redirecting</p>";
            $data['url']="board/view_thread/$forum_title/$thread_title";
        }
        else {
            $data['time']="12";
            $data['info']="<p>Creating Post Failed</p><p>Wait for auto redirecting</p>";
            $data['url']="users/create_reply/";
        }

        $this->load->view('info',$data);

    }

    


}?>